#!/usr/bin/perl

# build is part of qorgboot.

# qorgboot is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# qorgboot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with qorgboot.  If not, see <https://www.gnu.org/licenses/>.


# TODO: Build coreboot and ncurses config etc

my @SupportedBoards = ('T400');

sub help() {
    print ("$0 -- build qorgboot\n");
    print ("$0 ich9gen -- Build ich9gen");

}

print ("Checking for coreboot...\n");
if (-e "srcs/coreboot") {
    print("Coreboot exists)\n\n");
}
else {
    print("Downldad coreboot\n");
    exit;
}
print "Checking for flashrom...\n";
if (-e "srcs/coreboot") {
    print ("Flashrom exists\n\n");
}
else {
    print("Download flashrom\n");
    exit;
}
if(not defined $ARGV[0]) {
    print ("Missing board\n");
    exit;
}

print ("Everything's okay\n");
print ("Bulding for $ARGV[0]\n");

my $HBoards = map {$_ => 1} @SupportedBoards;

if($ARGV[0] ~~ @SupportedBoards) {
    print ("Supported Board: $ARGV[0]\n");
}

else {
    print ("Unsupported board: $ARGV[0]\n");
}

print ("Copying configs/$ARGV[0]g to coreboot...\n");
system("cp configs/$ARGV[0]g srcs/coreboot/.config");
print ("Copied\n");
print ("Press enter to make\n");
<STDIN>;
print ("Copying bootsplash image");
system("cp -v img/bootsplash.jpg srcs/coreboot");
print ("Bulding crossgcc\n\n");
system("cd srcs/coreboot && git submodule update --init --checkout && make crossgcc-i386");
print ("Building coreboot");
system("cd srcs/coreboot && make");
